#
# global platform config.mk prior to the local configuration
#
include $(WORKDIR)/config.mk

# appointed libs and their dir
LOCAL_SHARED_LIB := akuio akmedia akaudiocodec akaudiofilter akstreamenc \
					akispsdk

# decide locate what kind of lib
ifeq ($(COMPILE_SO), y)
LOCAL_SHARED_LIB += plat_common plat_thread plat_vi \
					plat_vpss plat_drv plat_ai plat_ao plat_its \
					mpi_adec mpi_aenc mpi_venc mpi_muxer mpi_osd mpi_md mpi_aed \
					app_dvr app_net app_alarm app_ini app_osd_ex app_csrv
PLAT_STATIC_LIB :=
MPI_STATIC_LIB :=
APP_STATIC_LIB :=
else
PLAT_STATIC_LIB := plat_common plat_thread plat_vi plat_vpss plat_drv
PLAT_STATIC_LIB += plat_ai plat_ao plat_its
MPI_STATIC_LIB := mpi_adec mpi_aenc mpi_venc mpi_muxer mpi_osd mpi_md mpi_aed
APP_STATIC_LIB := app_ini app_osd_ex app_dvr app_net app_alarm app_csrv
endif

LOCAL_LDFLAGS := -L$(PLAT_LIB_DIR) -L$(MPI_LIB_DIR) -L$(APP_LIB_DIR)

ifeq ($(CONFIG_DANA_SUPPORT), y)
	LOCAL_SHARED_LIB += iconv
	DANA_STATIC_LIB := dana_video_plus
	LOCAL_LDFLAGS += -L$(DANA_LIB_DIR)
endif

ifeq ($(CONFIG_ONVIF_SUPPORT), y)
	ifeq ($(COMPILE_SO), y)
		APP_STATIC_LIB += onvif
		LOCAL_SHARED_LIB += cloud_onvif
	else
		APP_STATIC_LIB += cloud_onvif onvif
	endif
endif

# support RTSP
ifeq ($(CONFIG_RTSP_SUPPORT), y)
	ifeq ($(COMPILE_SO), y)
		RTSP_STATIC_LIB :=
		LOCAL_SHARED_LIB += akliveMedia BasicUsageEnvironment groupsock \
			liveMedia UsageEnvironment cloud_rtsp
		LOCAL_LDFLAGS += -L$(RTSP_SHARED_LIB_DIR)
	else
		APP_STATIC_LIB += cloud_rtsp
		RTSP_STATIC_LIB := akliveMedia BasicUsageEnvironment groupsock \
			liveMedia UsageEnvironment
		LOCAL_LDFLAGS += -L$(RTSP_LIB_DIR)
	endif
endif

# appointed link lib
LIBS := $(addprefix $(PLAT_LIB_DIR)/,$(patsubst %,lib%.a,$(PLAT_STATIC_LIB)))
LIBS += $(addprefix $(MPI_LIB_DIR)/,$(patsubst %,lib%.a,$(MPI_STATIC_LIB)))
LIBS += $(addprefix $(APP_LIB_DIR)/,$(patsubst %,lib%.a,$(APP_STATIC_LIB)))

ifeq ($(CONFIG_DANA_SUPPORT), y)
	LIBS += $(addprefix $(DANA_LIB_DIR)/,$(patsubst %,lib%.a,$(DANA_STATIC_LIB)))
endif

ifeq ($(CONFIG_RTSP_SUPPORT), y)
	ifeq ($(COMPILE_SO), n)
		LIBS += $(addprefix $(RTSP_LIB_DIR)/,$(patsubst %,lib%.a,$(RTSP_STATIC_LIB)))
	endif
endif

LDFLAGS := $(LOCAL_LDFLAGS)

LDFLAGS += $(addprefix -l,$(patsubst lib%,%,$(LOCAL_SHARED_LIB)))
LDFLAGS += $(STD_LDFLAGS)

OBJS := $(wildcard *.o)
LD := $(CROSS_COMPILE)g++
TARGET := anyka_ipc

all: $(TARGET)

$(TARGET): $(OBJS)
	@echo "CONFIG_DANA_SUPPORT=$(CONFIG_DANA_SUPPORT)"
	@echo "CONFIG_ONVIF_SUPPORT=$(CONFIG_ONVIF_SUPPORT)"
	@echo "CONFIG_RTSP_SUPPORT=$(CONFIG_RTSP_SUPPORT)"
	$(LD) $^ $(LDFLAGS) -Xlinker "-(" $(LIBS) -Xlinker "-)" -o $@
	$(RM) *.o
ifeq ($(DEBUG), n)
	$(STRIP) $@
endif

install:
	@$(CP) $(TARGET) $(ROOTFS_BIN_DIR)

clean:
	$(RM) *.o
	$(RM) $(TARGET)

.PHONY: all install clean
